﻿Imports System.Xml

Partial Class Admin_Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim newsFeed As New List(Of newsfeeditem)
            Dim x As New XmlDocument
            'x.Load("http://itracker.codeplex.com/project/feeds/rss")
            x.Load("http://itracker.codeplex.com/project/feeds/rss?ProjectRSSFeed=codeplex%3a%2f%2fwiki%2fitracker")
            For Each n As XmlNode In x("rss")("channel").ChildNodes
                If n.Name = "item" Then
                    'For Each nn As XmlNode In n.ChildNodes
                    Dim _item As New newsfeeditem
                    _item.ItemTitle = n("title").InnerText
                    _item.ItemUrl = n("link").InnerText
                    _item.ItemAuthor = n("author").InnerText
                    _item.ItemDate = CDate(n("pubDate").InnerText)
                    _item.ItemDescription = n("description").InnerText
                    newsFeed.Add(_item)
                    If newsFeed.Count >= 1 Then Exit For
                    'Next
                End If
                If newsFeed.Count >= 1 Then Exit For
            Next
            'fallback when nothing is available
            If newsFeed.Count = 0 Then
                For Each n As XmlNode In x("rss")("channel").ChildNodes
                    If n.Name = "item" Then
                        For Each nn As XmlNode In n.ChildNodes
                            Dim _item As New newsfeeditem
                            _item.ItemTitle = n("title").InnerText
                            _item.ItemUrl = n("link").InnerText
                            _item.ItemAuthor = n("author").InnerText
                            _item.ItemDate = CDate(n("pubDate").InnerText)
                            _item.ItemDescription = n("description").InnerText
                            newsFeed.Add(_item)
                            If newsFeed.Count >= 3 Then Exit For
                        Next
                    End If
                    If newsFeed.Count >= 3 Then Exit For
                Next
            End If
            rptrNews.DataSource = newsFeed
            rptrNews.DataBind()
        Catch ex As Exception
            'eat exception
            lblMessage.Text = "Unable to retrieve remote feed."
        End Try
    End Sub

    Private Class newsfeeditem
        Property ItemTitle As String
        Property ItemUrl As String
        Property ItemAuthor As String
        Property ItemDate As DateTime
        Property ItemDescription As String
    End Class
End Class
